#ifndef CPFITTER_H
#define CPFITTER_H

#include <TObject.h>

#include "CpMagneticFieldMap.h"

class CpFitter : public TObject {

public:
   enum EDimension {
      k1D = 0, k2D, k3D, kLastDim
   };

   CpFitter();
   ~CpFitter();

   void    Print(Option_t*opt = "");
   Bool_t  Run(CpMagneticFieldMap* fieldMap);

   void    Fit1D(CpMagneticFieldMap* fieldMap);
   void    Fit2D(CpMagneticFieldMap* fieldMap);
   void    Fit3D(CpMagneticFieldMap* fieldMap);

   void    SetOutputDirName(TString str) {fOutputDirName = str;}
   void    SetOutputFileName(TString str) {fOutputFileName = str;}
   void    SetPolynomGradeNumber(Int_t num) { fPolynomGradeNumber = num; }
   void    SetfMagneticAxisIndex(Int_t index) { fMagneticAxisIndex = index; }
   void    SetMinMaxBin(Int_t index, Double_t min, Double_t max, Int_t bins);
   void    SetActivePositionAxis(Bool_t isX = kTRUE, Bool_t isY = kFALSE, Bool_t isZ = kFALSE);
   void    SetActivePositionAxis(Int_t index, Bool_t isActive = kTRUE);
   void    SetPositionsAxisFromString(TString str);
   Int_t   GetNumberOfPositionAxis();

private:

   TFile        *fOutFile;
   TString       fOutputDirName;
   TString       fOutputFileName;
   Int_t         fPolynomGradeNumber;
   Bool_t        fActivePositionAxis[3];
   Int_t         fMagneticAxisIndex;
   Double_t      fMinMaxBin[3][3];

   TF1 *GetFittingFunction1D(TString name, Int_t polynomNum, Double_t min, Double_t max/*, Int_t nParam*/);
   TF2 *GetFittingFunction2D(TString name, Int_t polynomNum, Double_t min1, Double_t max1, Double_t min2, Double_t max2/*, Int_t nParam*/);
   TF3 *GetFittingFunction3D(TString name, Int_t polynomNum, Double_t min1, Double_t max1, Double_t min2, Double_t max2, Double_t min3, Double_t max3/*, Int_t nParam*/);

   ClassDef(CpFitter, 1);
};

#endif
